import 'package:flutter/material.dart';
import '../../widgets/inputWidget.dart';
import '../../helper/Helper.dart';
import '../../helper/global_config.dart';
import '../../helper/uidata.dart';
import '../../model/SpaceX.dart';

class SpaceXAddPage extends StatefulWidget {
  @override
  SpaceXAddPage(this.spaceId, this.added);
  final String spaceId;
  final VoidCallback added;
  @override
  SpaceXAddPageState createState() => new SpaceXAddPageState();
}

class SpaceXAddPageState extends State<SpaceXAddPage> {
  final TextEditingController c1 = new TextEditingController();
  final TextEditingController c2 = new TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  upload(BuildContext context) async {
    var a = new SpaceX(
        0,
        Helper.GetGuid(),
        widget.spaceId,
        c1.text,
        c2.text,
        "",
        "",
        "",
        Helper.DateTimeNowString(),
        0,
        "",
        "",
        UIData.CurrentUser!.Guid);
    var pb1 = await SpaceX.Add(a);
    if (pb1 == true) {
      widget.added();
      Navigator.of(context).pop();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text("添加记录"),
        actions: <Widget>[
          ElevatedButton(
            //color: Colors.blue,
            // textColor: Colors.white,
            child: Text("保存"),
            onPressed: () {
              //upLoadImg();
              upload(context);
            },
          )
        ],
      ),
      body: SpaceXAddBody(context),
    );
  }

  SpaceXAddBody(BuildContext context) => SingleChildScrollView(
        child: SpaceXAddFields(context),
      );

  SpaceXAddFields(BuildContext context) => Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[
            Container(height: 24.0),
            InputWidget.getInput2("标题", c1),
            Container(height: 24.0),
            InputWidget.getInput2("简介", c2),
          ],
        ),
      );
}
